/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * 
 * Copyright (c) 2008-2009, The KiWi Project (http://www.kiwi-project.eu)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met:
 * - Redistributions of source code must retain the above copyright notice, 
 *   this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice, 
 *   this list of conditions and the following disclaimer in the documentation 
 *   and/or other materials provided with the distribution.
 * - Neither the name of the KiWi Project nor the names of its contributors 
 *   may be used to endorse or promote products derived from this software 
 *   without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE.
 * 
 * Contributor(s):
 * 
 * 
 */
package kiwi.core.service.reasoning;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.Deflater;

/** Computes Cantor's pairing for pairs and tuples.
 * 
 * 
 * @author Jakub Kotowski
 *
 */
public class CantorsPairing {

	static BigInteger cantorsPairingFunction(BigInteger i, BigInteger j) {
		BigInteger result = BigInteger.ZERO;
		BigInteger iPlusj = BigInteger.ZERO.add(i).add(j);
		
		result = iPlusj.multiply(iPlusj.add(BigInteger.ONE)).divide(BigInteger.valueOf(2)).add(i);
		
		return result;
	}
	
	static String schema(List<BigInteger> list) {
		String left;
		String right;
		
		int size = list.size();
		
		if (size > 3) {
			left = schema(list.subList(0, size / 2));
			right = schema(list.subList(size / 2, size));
		} else {
			switch (size) {
			case 3:
				left = ""+list.get(0);
				right = schema(list.subList(1, list.size()));
				//return "<-,<-,->>";
				break;
			case 2:
				left = ""+list.get(0);
				right = ""+list.get(1);
				break;
			case 1:
				return ""+list.get(0);
			default:
				return "-1";
			}
		}
		return "<"+left+","+right+">";
	}
	
	static BigInteger cantorsTuplingFunction(List<BigInteger> list) {
		BigInteger left;
		BigInteger right;
		int size = list.size();
		if (size > 3) {
			left = cantorsTuplingFunction(list.subList(0, size / 2));
			right = cantorsTuplingFunction(list.subList(size / 2, size));
		} else {
			switch (size) {
			case 3:
				left = list.get(0);
				right = cantorsTuplingFunction(list.subList(1, 3));
				//return "<-,<-,->>";
				break;
			case 2:
				left = list.get(0);
				right = list.get(1);
				break;
			case 1:
				return list.get(0);
			default:
				throw new RuntimeException("Something went wrong. The size of the list was "+size);
			}
		}
		
		return cantorsPairingFunction(left, right); 
	}
	
	static BigInteger cantorsVariableSizeTuplingFunction(List<BigInteger> list) {
		return cantorsPairingFunction(BigInteger.valueOf(list.size()), cantorsTuplingFunction(list));
	}
	
	
	static String compress(String s) {
	    byte[] input = s.getBytes();
	    
	    // Create the compressor with highest level of compression
	    Deflater compressor = new Deflater();
	    compressor.setLevel(Deflater.BEST_SPEED);
	    
	    // Give the compressor the data to compress
	    compressor.setInput(input);
	    compressor.finish();
	    
	    // Create an expandable byte array to hold the compressed data.
	    // You cannot use an array that's the same size as the orginal because
	    // there is no guarantee that the compressed data will be smaller than
	    // the uncompressed data.
	    ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
	    
	    // Compress the data
	    byte[] buf = new byte[1024];
	    while (!compressor.finished()) {
	        int count = compressor.deflate(buf);
	        bos.write(buf, 0, count);
	    }
	    try {
	        bos.close();
	    } catch (IOException e) {
	    }
	    
	    // Get the compressed data
	    return bos.toString();
		
	}
	
	/**
	 * @param args
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		/*for (int i = 0; i <= 1000; i++)
			//for (int j = 0; j <= 100; j++)
				System.out.println(cantorsPairingFunction(BigInteger.valueOf(i),BigInteger.valueOf(i)));
*/
		List list = new ArrayList<Integer>();
		for (int i = 1; i <= 20; i++) 
			list.add(BigInteger.valueOf(1000000000));
		//100 000
//6 3s2nntbcmexct6ji8lk1zqiayuelrpllihe7u4a9pgyxt151c8sx7		
//7 43n7ocem4n0odfhjbzayp2qw69hobgat1hncbkc55xwjyi6m05d7w7
//8 qvli3katkkr7wy1l8tkdbg2umlnr83sml11cslz6l8knpl7imlb9nw		
		//1 000 000
//8 21ian7zd4c0zvsgj08ckh3kwwrwyx8os5ia9zlzwltrnzlnz784hpel09gasjt9nw
		//10 000 000
//8 5l1uzssu7g7x32fyxuqoqcqvx29lj1d9499xa4zlutcrbont0mp78hisihtg7qiy3g06204t9nw		
		//1 000 000 000
//8 15s16tckqq558h8jjx6rv5gb1mh6epy2s9msb1bgmglntsjuz22mhq506x57b9fhqh1p2y7j9877gfykbt1t5zr4rpuat9nw		
//20 9b39cokeyozl7d6mwhttdwejmh96bta45paka3mtap93976gxz1xk3csrkdo1bwc9w6mdg9947i0oeumz8s8axtp10uaznzjjgzfhh2fu0xw0mkabnbpowcp0j4pm3u66vwklzopv671lwwzhr8odlgj9d7kvb3gjwzqfu5jnhw2q3cqqvz1su27c1z814ccmarae2nuo17gqok8rd3nmtgdmt42he6gxyimcdpeg0s484hybqek1gd8kozspwzc5qekpm6c8q8w2txu9bnny89extz1vu1kqfdzm75x7igm0sv5ou7709yhf0bsixd3pymx4ne8vk4w1xi8n2xzk0xmg9meiejbfscoj4rbf99xxfc2w286e		
		//list.add(new BigInteger("265296769244667534054059681525742309203931795164864263096320935325901537116951874047779671035838379338246988413488455235989509733710924060279579508415339077413829427794184345237366156880531505812721987432614879168004967599717398296657986440134540424123845905923452676838959554745086949001555306491296313180055071585945970564775317051046711975834544866075553621999218073717457132472232779127641712762085428810145252948632172888496088177233133891114103392630451172182815618948130826832386595807011414862285016540161514413441674271190423755218629286650367724839501491866236749666210139326855416992678291256464081773224068158109533750917619669621488099262447240994196845751988171296075413725327260"));
		System.out.println(schema(list));
//18376442694718396400348588964617143525843549196523551685752459105857216193228782197287733320863864102197695668389319253761851513580002934740725789442517900841211687723493013244303542052606764379788970308566694219773391558259634420583616301062465241233775184751514549196405554044945008276479212107886303612789295672108761281925093803683930821875108496374334482567121863259424070157205488494091366848541051057081980305369373418752894493331147418653321168342594143423309002700243948256902390071637629314317860785312995372103525708486248551132475467975320172186024422804661287824092204752420812578153219920735346753972784217150788751052022723321010745530043811532474931141813074102775374012826758802236728556493205239961020286339830693230599172446004400532893378341783757254676362833384099738829196508930985251228334087837373378485148391926118304846241885249294227432680180796865199972280282279090305618812279439353504295829351336738330988945656094600382752102393852334325061072349055233114798347698426852414343908744770051621582885324761463383403567964321030135302404171305901431218120219630443652525733427878357183272644763540677321549768139104886940274483791457506016984997085877001682142131775482768478819182191919767878556169384654050166532952556382376358182323580121808771124819705724982003126193084951828195195568127095794943632474207936004322105409652062311471909733645581144420444708879468441910457617139323773390929947728333175531414531895772739943811204131547017315662895543329307742035706716567655580456895139457641411148362311913340585261870416001275947658684888623783746807800920279538150228052741505741362912695232621848129249958566116733371798072308614578640278449809396633340003707180157183833182525828769717169670291224250501797414734258312826527389591636831781172003431876334516173524904004015364986256536410614384961397119812064843598329861989778342878384650916117885074134607764350758196891400868421231035145697233593111024282277486566922238587925529067676718456729144443444474781893805636665061846259865630891341798383165802295845905971413119078356287199989084377124646530006326822307607878847696890518428911078585025278080270524236306925921778952747918014636480556325779773884909524644071326838422373953755782662059380970895001907559755986164053179072928475454033383425287009979550798407172722233581436393920218610576314683953553905164026415370559617237201637566645747574870277527082062520703169222999252291693857262393581070866117530921525095650829909617030571135424141202771525611925746440201635126889901615875618613643212167915121681583751862385641535357363264269130681173140175414241159674205983940817622894452810193245821099536978861294473060983468715015640930322534429796173164180306743985022376839915611141141062056313120452514454433473179858709828150989764349883230336546962711228776360969355427935713065080952525168662533303105010903705640601718736618563100781892387754130407596834575360066539167586981960138473210839228820665913557805055874652428578131579878521790191624540267268197505879501975748082212599207893052562575159201719393233012345910446708015488887178408487675853978484445280679826592076315523357026668825472439089419366377265390285770777962337941678644998349212664732779691848399718125989928052728866612497945676226304120542685106581455721088881262026751114817261950818747900693248188616692111307584704619245785729595073718252437723938599531419560505620600161919293895463362032558102183827168368100014308518853153269461068258257481525405039918388669492653278743905687569973488378758993018379702693219345032807155094709347595394197346399402770999033345307908697814211811724760984750382932050579211695360496152310515782039039232578664244366878606716887730538144077120265640901248802712679500309431421013859893764498472693895956627227309775578667504771264543954779384989996287351047844683154409735350612076647022276968339744171024684827175782299937725092541154685232482548546164246037824199750729272260291505733128435981738264675979369366538197385720778311704444225945516160534058589633120530393055465069603080201668207573332785549623443729167208876992607805139458903463422276341492631884042178446484957027742912854613299720248874770244987421653139032935175312067607949740081942521243377341363395366747582374083807832001518533676676483790508319353439948312269567406975989166434571552554725160205279912015279808413988638506545779212612459034222476050163277440515769757431039830142510157185627704142258571988703260929731782789723083515403968214887078414552253755035729017306426710666358031993171654786199185523708824404099877933941507258725383542319281447848154190068220358172759162791759515448283029859925600741606528452789377029600108687033962642271464234438582927029643975106283618936476903553887813392199074573679962434872044544923139530247069132617743350657340709713174093896466711035365982981277555357238616140589924222537715973632696478455571489320302907648377756431182027077412497082594146429631220125158177619998876809576802290580034722492242705938772257243067744135074234462658113280109618123149984337914457891660208156980056483655347494124799215561800761861229494976872957418084206177688380340459877571152605189755387092460953534720673622436843122941811035590091779080623679132561599091668287217237306191270693563441005662941466834028848664914260703722252678434106344412117646728438079280234685450169782426024457483739446196836166946332603378034309941487101158126350162318623171374972666392356932696300248227215659242805416665190558019545348024569561621379097138378862783797542153637025947973562375462068232371195215970914821490287162116311211327017190460715517855095736819918951230613376058017434024470049495543556222565569045876815711576770075606791812067171507039128149694207575076853108893686108655917684492214384901009758800072820758682707449463746802649692651890548323861070656793968988435378710633283396710000047294456580286768075974830223422697014759922774085256924147007625190075515128081466875933495577948339305567003675556059260228590827961778316135316326281221419840361035168290155224193787558444410647873212750497306733270333902449731754417607274027759185443607281441840698517118097402311518254776147251241068998076991835301878921002210924576512674962488185537203018579546763460176818575167047601982859294839292543686792346398850329929158260029157567461317208795263664400139366354968158062232434638559201968482543015976194332276831722144638872316055215529259585254217401882562350172611237095977542708038392483933286140487800103489662953636244644098004527096070884257275857765671968135836974981458073539485475856003366779507484277137991632002318232514956937122339315524831791414451724772180444445637308535610614240312518085856063512020015700866942788369866803955724254066112612348343550305244195967478677992214093474421072512515265733791041358638869841598913092579112437494576463147892280933590330485396496982917995807584924219077162081866964848605608141446377043843331995101518955488820199020080339502199634045668186087733264821511148040716142089290344725038097536682250275948504132197900556486433926151145617580422460592498120968781050720368382282161808593161808227247925561813725601136562149131625609444602430108413927523213174666854165040790628129363023613511196209883673126968603924569367948188797554799450862246538151411479439699473203861360394200268316544611144867607984492170340975663856532985939178275322508546380482772565852229231516349112633850333233161965690352139841215956922826637956721678580691310488243799392379439831185424449024339950425262365904419065039661804735805947871645879358102686469995959619311855444399698698983663053464977570741729476231401923369187781298887967046370530151517639664810650903242756683451513847612498659209522008789369986786700896821495980039467325849573739814307170351932819902312755880021849183515767701270279533404833655811559566575353549806332281205905833530186345238189020110385896966409615268912008550658048274763146698946653618592104933060092962145366907593728798525649446999556732232652264571072759096921906942195190601987469730800967708586250058025398245358855926953239322098550590767367200605154575376446674039748756996256414492243820655201235068769744120469632039884883342463698292604177758982845305999902550119705824545158415694846017713749313728029368024315895048156104668305061900872610988971224046387692558358296840973273841792193066845802601091877554211800180327343813785140074388565739455725994415301954636707190437602150857521783842862454796141507365075178002375837006592219338121574991530104310685609659373625052786444428546231061886414206542513850802488796958171306990574842168058157309306203130580444912484903020472861636709680875083798616049450893909145616878980091605884201153255466354636881896526665744791505547606292516815053418811447352066996818812443999177022506363550508409757820359704345478183800159200017578398428665494853827117198741846393708690552626743472733448427093061585990999913858168073026614272414728640620515144356549782175362618914334891559346331483701275392177553198891542014322494987814055812975793674946218492905234362114469487213369403420134542424703096442624119521137086107139485711590947386365315911965497288869923281873045351075164618998277271905735792850020430789001411208348940768609569424621652094398642793852258252316623990540294928493257484039579713357628988927218125343657437807399382975074882796289758473897583230707321409620767986280594019423900749447731613439684507329160424522881705764361989182557836294327654788762497343042392721181929772408918744868139175764116996079014046655359893188175378479127306929794925405688178179038454543017450753079791194152944337220717512515294996557806836976567501528108875137391416953875810441634247697027522701936977969943565684675439037378936551612402466411423244524198275651741204282047048457932946725085143836025280123139625339272383049585849633512455422345062347990536314641593598887756248665387487821399581431085047624686457731138688900916798097179056832771745042898656570074771282447154093987626173208119319378683369488664344577002058878070675419495441142248836189663889107376714226549886980798869657910419459679208707895076725624030352076376588315338607907778524280366904654079312168321058319461600513626703325383782253069387726871550217965882496354737535770579168945130984698468406223840360451313598864297390804907706649247417966683959019706539823356442565141248109682950754766327893779816296095659508792886873576319289513653346510647481827986520719919964582223724997214423251419649034654303355083764776190497016593577716072404301897345144731823118153686835607736033361460579132723894255299361712042227087586111076054821367736939012359445536116133257649092816084591587999622761081253352588005766590834928068379460868684938801114338822088316994540752568400028994585022008795695156953289373671681662551255255901557299410559437823234562873903138701415696242365116556146198123961535987833301973859815038657130642428785513959761104623593635610770126157069385559688066510627305784424623821085251214427713257816329046804926413627446237784501582386998460036361745069312035495792760			
//euwbts5a5ofytfxz6dkn6fwejim2i1xck53szxbqo0xhikogk1g3mf6v166n3tigeuhtl6dng5j8i4bq2fw1qskn31d2jvhpud96t9gsbcn12lr8t68b4opx5itkwjy6itjau42eh64wx6d8hi95etdyk2w3bxnuhb3ehez6ozpzq0w4q60xryhluzs7h9tdy1vt0a557ergv0wao8i8olmbwikf058psvj3j9n8v897ksgybkj2gnm9nrzjobm1w6cyhz6uo3ibw89nc5kvk199icn4uur34a83p02f5j0w3b7r36pi4s83lg72yur1358dzs4ky70mar7irx834uegg7wv38guvrc1uvdv5rh48p5x4gjx8h7uen7v36zdsn8hmqp90kpr1uvvoupbfh6ggamnx60k5qgou3aiiw722amipab4jdmrgy67410dicbp1ts6wcizf913mc72bkkb3w8a4t0yyy6ifsbpsb1whx3eif5l4p4hla9j7daxhw2xfnv77yn69vpz7fq5vjmxwfbvu1isuiqcqyub1rje6qiws3jhp1kmsad1u3ht8anxvo22lciwbzf02rfaqvmwqakl3x0sruhwrj2r9bplk1wnd4w3s93zpsil2cxzvee59qbmp38pypl83u7gigvo111n1m922xxh7utjkidaqshwzo01hi803i9cbdgp34sbf1marryu0ql2gvv8nrmpthjb4uaka0vqkdsdvqy7tx48duq8isdplfx3wgnidztx2n78bzf5wzdqwb75h80rv06i78ibpa9af00bebjmxjr6o9iha3ce9tdxaguztkc1fqlh0er96whoc7re7gkkw8hcl0h8wy7kgwfg272kuzljddf619hqaizovliu9rukhgj1jpur84ycdu3yw69a060fmgp8qi7yrnckhoyno9a5zsfimev5auu05hn2psrii00w8zge545e2us65vc6yymful38zfop0463w9xdbkfl5tpux9y9xjlo3fvq0fznlrepan2vxvfq0i79hcivbcoadqkqx1wtxfp5jiw4hro1rs0c1ds3lpizhlb4lo7kge95x8gd8oypxlqenzszd77vvd61zdk5gjxfgcmqgka5b6lp9bdar8o0bsqqoj39v588iw5fshw0c5krdls420siaw3ea0x30pkm8t5rjx8pal2kkgri5weg99lxi1xkipldlkyo3zyd7emhqebpjw1o67827oezy1jfa8hvoek51ark4qpv99z4fs4va5ss1bmd0dl09d6jkxixzbw7l9fsmnddmg0y2r67vy5wmlrhnh0lwlojnfflcpewcot1wpemb1g2qcg1w2nu786g9fee4fsemsvtffss43ejfnc2evca52tmk32hk73086at7ou79zvbjb4cjhkvdw5cxxrgz9vpx5p2ze860ah2y4g8njidmcqiqrzhs4672q2fhdavzjdw0o1noq3xj1vo3apbrbix0dikcp6azd9jmdhbah01y85hyerumy1fvu855kbswrfypc93nkldxz58g4c686nbr2aqlamnbuve06qawe7lq8qwlbqnqz0beg6iq65ozxsdzhk5s1ang50u1lrb2f8d3okwhqbq9796u061fqfzhobep2uayrhp34klow36agst518wxrwao2j2qheg0wthgqrqu10axeb1e0bz46l6mwyhz31tun3pi59b4eiy3kv9ykvqoz9x9t2hheyihxk4jkwf651819ju02zzypci4f0pon3n4wazba7gq7u4wkmh8nzxd9dsjw5j8im0nxghks9yn68wnxxrc3fakkddd1qj3l9dqse6lv7z2au8yqhf1yt2vqaum3fxxjax57yg3xxf3nxkbc7g187tx9kmgnb5nvnkq7lrkw4t1lsphb1k229krhq4ghqrw7wc6hs785wmlmqhegaftppq54y6ki8xzubiqgi4j9n8d8du679n8wvf116enooty68szer8foqu2hziuu2u4toe3h5whsbpuiznbh9bi84syhaj7qvzb1h0zjreqiwnt1jecbit5ia84fljace6v7kos7z0pxtfbw0k1c5yxqvpqjizpwwg903msq6tu1011qjewask02glnxq1ae3wah3hc4au8vzdxrm1hlpzyfid2g3o97xdus8kuc0nz4gr5yzbywftqv4owrjey9e32dbvbfolp1ebpoqqob926sqd9n11rt8j0frmtubpka19ms1lvapfvkba5grtgkfbherazid0puh259ppjb14k4j9m2ikdwpd8g7s5z62jm58tenwe9hum5n7ag4d7plwyzivteab1kakz0j6vdnb1gh7t5f5w7tq18k6ywhzfeowhr366f2bbvm4yqk2v31k9p4ot3ik2ixu1vzk20wrr92b1yaddwnh45qyat6rh1ie2yapiyxvwfhp4nrexta8bq12dnxmuclt8nrea5kymp18t1aie980dve40vk1edp2ph9mtcxsjpkhl6jnj7m8q9yw6c23jjzhbkor3uvpugvx8t79xfpz5cf2afp5qsnn1dqiieq30h3x0n0ymckw57bito8a37y7inf077b0cvhgmwmdfa86scbbhgdsulx4dkv2tkfsadr1i1crsry2r6hg7sir9dzlxteur3ipcezscyasv8dzvuyonfpras5w474vqxio6beegzgeoc6few5to3uok3fra50x75agsiih5ighrp9ov8g9p1m8jf1bpyiql2ho10gnpzbb4j7v07y6f6v2psnidkvbaovq1qamparxw7vwlr16b2xq71oo044a7oht7zo97atguaezsftpbwsg23gd91qk2kvwr89j0jh96kkf1cuh0hnr00x8tn3ed7qloy529zcdbvo38srtyhkwcik9oya1i2slc3ztwprk1l7et1rj749ucbw0o00xp94wvmrmznradf9u9qhv7zjexxb69nndqa6tdn2wxgs76625779yfz4hp5luy0qurvtagxy2pd2fvpnwr441a6wqyniqj8ps749v7pu02if334qol4q4bp3zoun5s61q7n1b1r9b36ceb70ntgjko2sajv68ozl92si46yat5f0rw6rn4sfyt3vzk1au21c1f2k0n4iz2f2geoidklo3x6u1x6k0ql3h8u0xdpxi7l7v80suxpr2975y7pmxv2d46zxnu4bwcr7j2hkupeizbmlrrntwuvoj0uy0ficy9d2ija9vzwzcuigyou2f7zfbsmkjg63ktz39lishb7lokgq91z4uel811biycakdzj19j079bl4qhnxr2u5nyqfncriw7o4333aykyi6ao842cqtjbzka508dvxt08quyv7b6ui8auir0izp2dwn3mclaki4iptw2kq04lxfilem33rdagrjsje981g8yc2gol1025led8mvbnfc0ssesfdm6sievmkx6pcwnwg9vpv9cogvnu8xfv4tchtgie8shnjvbu1451smsmxrtelk65qk0k2x1f6otr6qz3ce2swdemd9oqo5vw0ktglmihehzozpt33h6jdh3vbtlzriimi6zq13zwwnz0j7alvmkoiskloowaoe0759nvk73mjzx9pdb9nay830nj379u5drtncpwlvwrebck4ix6wdh09zhat1k8ht8asdvwu49e4nrlep9cqyvzkvuqh0h87jegbkfz09gi2g8d8cqdxvythv2isz5cfnf7khg8lkvttzjxklgqxqkgn8rs4qz08yv7f54dvfspdldqqjmdet9utoamy2ww7cfu2bfomo9es18t8d9s66ocw9pmpjsuuzmtb63c1ubm6jd1kxagp6sfvdeac5scka3nga5xdtsfjxn9nw2dllb7iq048dg4kqtkw344ppn8ing6zeezewbl2abzsup0fy1yp2l5m07gz9egpqw4ws61m9oh3pxxmk3c2etkd28jvv7ehtqhq746hc00pu0nr6ust6ehnwuqyre3scltdbihlvptmezy9n19bgqmmc22msm35yn4qar9j4rwwvf5753c31gktrbvtstd1d5l8myrcihvdbfbtrtawhk7uymk37xqzonwx18tpaf0ivepl2s0kiaua7oxw1g04xy54zagitxkjt3opl17ncqic8owq6fzmd0qtwt86i6mfb1fh4h5x09du0xdbc8p7xm8k9rl1qzc1dwu4z35jjo84aicnx997r6u9msu65yiplgbtwq0xnqylap150xxj90ml2ahbtik6wsh5ubsti1wz11coch5acy1dwnyua709i42kgla8mejlno3a3443tfmlgqablq66c96mdsw8lltqriedi0pwyo2ui6l5yth290gtchmr501slndtme8z76iemj1b9as1ytwymj9kqp8xqurn3h1k9gq3oedtpp6cs2mm9sycg8nthnkjgkqbk43llw59be4dpi86s0d64n8pi6f7borjo3150aazlkk4i7ykg0cfz8laav0b5oe0att4np9sr6ahfxbu2iztqdw8yi60nx0zae1secegzehgzvcd4synygp5c89nzng88chrou8ig1el1ovxqppamlbehet7b8dl4cbcu9gcu0uq5h4ju83ipaqyqsvimwn8919l52dlf70egm8vndxka8jx540m5jxoiv54eh1autvlvjim15esgbwalzpca6ene13ftp3hxa6elefi762cu8c5dp7ea82z24n65652docbx69yrlripx2inz4owbxhjztf78t2bfv0av83cx1az5p4tfbv7tyr9ry2hs70ivxu6cdzi3aj6542ic3ztzazl70p40ltgx7q2wd78ver0njvyadjetmr6tx787u5tapq2ngghvyql29bl1jspgdenzy7uozltxobwj7160byzivsx05e24wonq5djis0rr7nci6qcxiyzrdxr2rlxyye5el1a5fgvyplzfbwv6dtz17dwgnyb5vhpukm49rm3plgrqr653c3g3ktx2xywnuxg5crjogrdvlo0rq724n3co14c0xyn26wthfg76o4g6vx5xnsltfv5e2qq0n6ome3g9pcj7kuuwufv0tf641qa1jmur49st6692urfuui3q13cvehpc9cmp5jrps3h7j9t3tseyim4591unktaehj32z7q0oswpg2y11ukd2r0q29icg8eo8bz8sd4h9axphch6ooqgck5ar5ird5cg6hu3denpnexzgr8d2pxzqwjzg1v2wgxundbx46dcufje5jxyrew2ngrsktcn5vatrqofkl909kcm1kd86x6255aiq223ej5n7zwbdvy1ivudg2kvo8yftzglcjr4txgf4qbl10ml7wir0c638r40lx9ps8x6wbsxkeorixrkhp94t5z58m7a67qefdjkwj1tfw9mr11w6fmpzleah7utsxinc67cyff0zlwjmvku0dbw0632fyu1jhwn1nlhhsji07agujc7d5mhg8kjy2xnhb1sfduurg78i75tyrp0a0148vc7ouf4iy58bzqcj2zmh6t07mnch57bcdszl84c1hj4t5ucwpdx04y4qvdidir5ew5o6588z4nmlfj7in6p4csqcs7vtbac58ovgs0i960ioe5npocgtwu83kds6b931mmwz1kxipqd88ezcsr4l3vqsuphufuza6jwalg711g7vof8cd65dc18bg1c4rppsliyfp0vtevr9kmr77o4bgg67ql7r7ss7e829vaqenjasgu89sfnpqrn7dwy8vfl172zocockiey4ie12zp4vhmbts2247zhl1voiowcb0zl8rnrwpw5i30viqmc4eihrtxr0a14nncjg6e9misu5emq1qurk1douffc6ifl27bbl2c3yzrurhxrshme0dbxhs2vxjfxbwd5c2q7yr6s39rt9pf6u1x3xhzzi65r4gtumpgnzlaaqb5qz6r0axhlxchaimnybdtzzftrud4kcocdhrob65vj4ypp1n14wj7vssbtchtj5ffsjx8oil8xrnw5w2q4c7ct67bhaimfx0yijapk2gpv9smwjbtcyfr3exdyu01oqr2pjbo6lb01b829uwpd3xnnmlgzfaopydme648poqm54l1guvq0xxr0o5ubrl3oz73ny39wigcvi8p2m1nvvjs6i9oqxfzdv48bd87gxnrczp9lft5lmzpdq2ifvdpx6nv2dyp0vl14ypkiz2l6o8ustlrxfdwkeszyugquexkdenk1aktvz18vcp2rfoju8qrnu1sapjbw0rsoxifo6d0ikkta54jam44hxbd1qviug90k0zzlehac9js2u4oc5q3bgcwoz4wv0hm0qkl4mv0euulvd8bdijm27amhwkar19tljp2fda6qvl5klxlbt2ikcm1dfzshilgqcjoqhrospdktj8aelx6jyq0zmji7t9gdivqxjswvtzgyrqpqovev3bp8e63uh2sjpzzfc5yxauhxq3yx611d8qey2y800m6nreeo7ze71pxati6rpkl7k6vbi25f5exs6ip5ub7gruxe3kgls0hai76ne0o872fty44kaendggyhzf9x9fp3cim38pljjbwcfdinbj7b2j9iw3dh8mh9jatyoj1fu3c53wzt9vi7crxvgncbkhtztgd7avtwbx0ow0i9ymyej02ask401jsqu181rrtmy8qj0jjagky21sv73pe3rbvs54qjwxwudzh2g5fvlx6vgam991dvxdrquq7q8c63gt1087870hr8vg64f5m3hyol7jq4il0nwp3c41uz474su8padqbw03rprkjs05lbfsomeucvo3qg1r1kfzrvbh650q493z6yaq69hwv6ri0cm6gp03k359wb1y9gyn9orciw7dahrny800safdu7pkkqt344c9zp8yjsur0nxsluipt1mui9h2maoe2txfemuw8urgzr0p0lohjknvg2s66wiugyz3yqjiegcibq54mzi6bgsxn0ilobn6jhzb35709sage3g32qoshemlsafycki1jc21p2fnpusfs

		long begin = System.currentTimeMillis();
		//System.out.println(cantorsPairingFunction(BigInteger.valueOf(16),BigInteger.valueOf(16)));
		//System.out.println(cantorsTuplingFunction(list));
		BigInteger result = cantorsVariableSizeTuplingFunction(list);
		System.out.println("cantorsVariableSizeTuplingFunction(list) = "+result);
		System.out.println("cantorsVariableSizeTuplingFunction(list) = "+result.toString(Character.MAX_RADIX));
		System.out.println("compressed length: "+compress(result.toString()).length());
		long end = System.currentTimeMillis();
		System.out.println(""+(end-begin)+"ms");
		//System.out.println(Character.MAX_RADIX);
		//178821086431539603524
		//9b1a41eacbd57a844
		//665e5808b8c61ca4b582ac9afd243
		
		//33220487553178432294531283842748995
		//1231086016963894021655067813655356182
		//650893016940996777738916166665377667219882515301356849075485286672712233074362165746115
//8g0d473ba2ec67mbj3ddl01idcki06gna21i23e2m7kldi4ai0acfgmjjh95khg7146j8b7ih416e91dnjchbd4k8g5h4j24k7mk4cd0e5k95i3kh290j67n48l5bnn54f1b0l9k4e5emkf0nb2ek345j7f427gmim2l0jd4ej86mh5mji77b5058b37alhbhkbdeibm4c9hcncl96j2dab4j0m0449d6i4jc24nk82ek29mag68h1n45hhd8ln0jacm3afb8nda57ffl16aacbk23gll41bkejain2cl1ji77873kal8645khh50l79hjfhgb5a8mb03lie278jdfjc72dbd2d60f392bnbig5d21n11m52i2n66gbfbndjlncil4256nn6h8an5dm4angfdejmff9798a5h6f94b8gf44ebb0d2flhif2g8nae65821a8mb57hiki5m1k1i803mckc00356gkc45e6ml9i05fd0l4394
//qmshmo6znfvd9qy9ejsmrfptcftzxruqssagsain1qmlspopnb3op0eeqdf1djn386a1jrq14ab20pkpyox3l1aj7zvvovolhlwbpht39jo3sf5fgej6xz2zabc4w82l0dnmyee0vplk7u6wo6angaiarodwqydv7o31ow38u9g55gwccl155gde1u4fhq8jz7e7jtooj2cmag3a1up46g9re803ututwpu3l7h3cm14b35lfdo99eg1b30cdm8b5mwvjkjd2yx0lj0kjahjd7hp0xik16sf1qtmq92pmmbhla8qvwebfc82bg9cnvi2rbrdipa209v1pl79e6j37zt8g7sxj7js4nfodxt86t52y5q3cieybvwf2h0ebywdbiy1561jeunivrj10u2aripe6f7h83u8ve31jqofi9y1lj9f3107me5l7ak64

	}

}
